// 路由懒加载
import router from "@/router";

export function filterAsyncRoutes (routes) {
    let res = []
    routes.forEach(route => {
        const temp = { ...route }
        temp.name = temp.path;
        temp.meta = {add:temp.add, delete: temp.delete,update:temp.update,query:temp.query}
        if(temp.parentId === -1) {
            temp.component = ()=> import(`@/layout`)
            if(!temp.children) {
                temp.children = [Object.assign({}, temp, {
                    parentId: temp.id,
                    children: null
                })]
            }
        } else {
            temp.component = ()=> import(`@/views${temp.path}`);
        }
        if (temp.children) {
            temp.children = filterAsyncRoutes(temp.children)
        }
        router.addRoute(temp)
        res.push(temp)
    })
    return res
}
